<!--
 * @Author: 敬华丰 2637844016@qq.com
 * @Date: 2023-05-25 15:39:17
 * @LastEditors: 敬华丰 2637844016@qq.com
 * @LastEditTime: 2023-05-30 14:20:28
 * @FilePath: \imedia_crm-branch_v5.0.1_0518\src\views\order\order\components\c-contract-upload.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <!-- 上传保函 -->
    <el-dialog title="上传保函" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="auto">
            <c-form-template>
                <el-col :span="24">
                    <el-form-item prop="files" v-if="dialogVisible">
                        <c-upload :disabled="ruleForm.disabled" @change="$refs.ruleForm.validateField('files')" v-model="ruleForm.files" listType="text" />
                    </el-form-item>
                </el-col>
            </c-form-template>
        </el-form>

        <span slot="footer">
            <el-button :loading="loading" @click="handleClose">取 消</el-button>
            <el-button v-if="!ruleForm.disabled" :loading="loading" type="primary" @click="handleSubmit">确 定</el-button>
        </span>
    </el-dialog>
</template>
<script>
export default {
    data () {
        return {
            dialogVisible: false,
            loading: false,
            detailsLoading: false,
            ruleForm: {
                files: [],
            },
            rules: {
                files: [
                    {
                        type: "array",
                        required: true,
                        message: "请上传保函",
                        trigger: "change",
                    },
                ],
            },
        };
    },
    methods: {
        handleSubmit () {
            this.$refs.ruleForm.validate((valid) => {
                if (valid) {
                    this.$confirm("是否确认此操作?", "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    }).then(() => {
                        this.loading = true;
                        const url = "/guarantee/upload";
                        const data = JSON.parse(JSON.stringify(this.ruleForm));
                        this.$post({ url, data }).then(
                            () => {
                                this.$message.success("操作成功");
                                this.handleClose();
                                this.$parent.$parent.tableList();
                                this.loading = false;
                            },
                            () => {
                                this.loading = false;
                            }
                        );
                    });
                }
            });
        },
        handleOpen (item) {
            if (item && item.id) {
                this.ruleForm.id = item.id
            }
            this.dialogVisible = true;
        },
        handleClose () {
            this.ruleForm = {
                files: []
            };
            this.$refs.ruleForm.resetFields();
            this.dialogVisible = false;
        },
    },
};
</script>
